<template>
	<view class="app">
		<view class="price-box">
			<text>支付金额</text>
			<text class="price">{{info.order.price}}</text>
		</view>
		<text class="mix-btn" @click="confirm">确认支付</text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: "",
				info: {
					order: {
						price: '',
						ordersn: '',
						issend: '0'
					}
				}
			};
		},
		onLoad(options) {
			this.orderid = options.orderid;
			this.$axios('Pay/main', "POST", 'order', {
				orderid: this.orderid,
				apptype: 3,
				code: '',
				iswx: 1
			}).then(res => {
				if (res.data.code == 200) {
					this.info = res.data.data
				}
			})
		},
		methods: {
			//确认支付
			confirm: function(e) {
				this.$axios('Pay/goPay', "GET", 'order', {
					type: 1,
					ordersn: this.info.order.ordersn,
					apptype: 3
				}).then(res => {
					if (res.data.code == 200) {
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: res.data.data.timeStamp,
							nonceStr: res.data.data.nonceStr,
							package: res.data.data.package,
							signType: 'MD5',
							paySign: res.data.data.sign,
							success: res => {
								if (this.info.order.issend == '0') {
									uni.setStorageSync('upOrderType',1);
								}
								if (this.info.order.issend == '1') {
									uni.setStorageSync('upOrderType',2);
								}
								this.$navTo('/pages/index/order');
							},
							fail: () => {
								this.$api.msg('支付失败');
							}
						});
					}
				})
			}
		}
	}
</script>

<style lang='scss'>
	.app {
		width: 100%;
	}

	.price-box {
		background-color: #fff;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 28upx;
		color: #909399;

		.price {
			font-size: 50upx;
			color: #303133;
			margin-top: 12upx;

			&:before {
				content: '￥';
				font-size: 40upx;
			}
		}

		.p_total {
			font-size: 30upx;
			color: $base-color;
			margin-top: 10upx;
		}

	}

	.mix-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 630upx;
		height: 80upx;
		margin: 80upx auto 30upx;
		font-size: $font-lg;
		color: #fff;
		background-color: $bg-color;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(96,43,154,0.4);
	}
</style>